package com.shunde.xunjian.controller;

import com.shunde.xunjian.service.impl.ComplaintRegistrationServiceImpl;
import com.shunde.xunjian.service.impl.ReportOrdersServiceImpl;
import com.shunde.xunjian.service.impl.VerificationReportServiceImpl;
import com.shunde.xunjian.service.impl.XunJianServiceImpl;
import com.shunde.xunjian.util.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@RestController
@RequestMapping("/XunJian")
public class XunJianController {

    @Autowired
    private XunJianServiceImpl xunJianService;

    @Autowired
    private ComplaintRegistrationServiceImpl complaintRegistrationService;

    @Autowired
    private VerificationReportServiceImpl verificationReportService;

    @Autowired
    private ReportOrdersServiceImpl reportOrdersService;

    //巡检工单数量结果
    @RequestMapping(value = "/ReportOrdersNums", method = RequestMethod.POST)
    public Object ReportOrdersNums() {
        return Results.success(reportOrdersService.ReportOrdersNums());
    }

    //设施编号查询对应坐标
    @RequestMapping(value = "/facilityInfo", method = RequestMethod.POST)
    public Object facilityInfo(String facilityId) {
        return Results.success(xunJianService.facilityInfo(facilityId));
    }

    //空间查询周边设施属性信息
    @RequestMapping(value = "/WorkOrderInfosByGeo", method = RequestMethod.POST)
    public Object WorkOrderInfosByGeo(String wkt) {
        return Results.success(xunJianService.WorkOrderInfosByGeo(wkt));
    }

    //巡检工单台账展示
    @RequestMapping(value = "/ReportOrdersResults", method = RequestMethod.POST)
    public Object ReportOrdersResults(String reportOrdersStr, @RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws ParseException {
        return Results.success(reportOrdersService.ReportOrdersResults(reportOrdersStr, current, pageSize));
    }

    //巡检投诉台账
    @RequestMapping(value = "/ComplaintRegistrationResults", method = RequestMethod.POST)
    public Object ComplaintRegistrationResults(String complaintRegistrationStr, @RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws ParseException {
        return Results.success(complaintRegistrationService.ComplaintRegistrationResults(complaintRegistrationStr, current, pageSize));
    }

    //核实上报台账
    @RequestMapping(value = "/verificationReportResults", method = RequestMethod.POST)
    public Object VerificationReportResults(String verificationReportStr, @RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws ParseException {
        return Results.success(verificationReportService.VerificationReportResults(verificationReportStr, current, pageSize));
    }

    //新增巡检投诉
    @RequestMapping(value = "/ComplaintUpload", method = RequestMethod.POST)
    public Object ComplaintUpload(String complaintRegistrationStr) {
        if (complaintRegistrationStr != null && !complaintRegistrationStr.equals("{}")) {
            if (complaintRegistrationService.ComplaintUpload(complaintRegistrationStr) == 1) {
                return Results.success("投诉成功");
            } else {
                return Results.error("投诉失败");
            }
        } else {
            return Results.error("投诉失败");
        }
    }

    //投诉核实派单
    @RequestMapping(value = "/dispatchReportOrders", method = RequestMethod.POST)
    public Object dispatchReportOrders(String reportOrdersStr) {
        if (reportOrdersStr != null && !reportOrdersStr.equals("{}")) {
            if (reportOrdersService.dispatchReportOrders(reportOrdersStr) == 1) {
                return Results.success("派发工单成功");
            } else {
                return Results.error("派发工单失败");
            }
        } else {
            return Results.error("派发工单失败");
        }
    }

    //投诉列表数据行删除
    @RequestMapping(value = "/ComplaintDelete", method = RequestMethod.POST)
    public Object ComplaintDelete(String complaintRegistrationStr) {
        if (complaintRegistrationStr != null && !complaintRegistrationStr.equals("{}")) {
            if (complaintRegistrationService.ComplaintDelete(complaintRegistrationStr) == 1) {
                return Results.success("当前投诉单删除成功");
            } else {
                return Results.error("当前投诉单删除失败");
            }
        } else {
            return Results.error("当前投诉单删除失败");
        }
    }

    //投诉详情页
    @RequestMapping(value = "/ComplaintRegistrationInfo", method = RequestMethod.POST)
    public Object ComplaintRegistrationInfo(Integer complaintId) {
        return Results.success(complaintRegistrationService.ComplaintRegistrationInfo(complaintId));
    }

}
